home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / dskutil / colrboot.zip / CMDLINE.A86 < prev    next >
Text File  |  1994-10-29  |  6KB  |  173 lines

  1.  
  2. ;----------------------------------------------------------------
  3. ; CMDLINE.INC
  4. ; JIM TUCKER <jtucker@adam.com.au>
  5. ; Last modified: 20 August 1994
  6.  
  7. ; LANGUAGE: A86
  8.  
  9. ; This processes the command line for switches, drives and filenames.
  10. ; It uses about 240 bytes. You could do it in less but I have put
  11. ; emphasis on readability. To encourage beginners I have commented
  12. ; more than usual. - JT
  13.  
  14. ; 1) Just returns if cmdline is empty
  15. ; 2) Makes cmdline ASCIIZ caps
  16. ; 3) Puts switches in a buffer and blanks them on the cmdline
  17. ; 4) Stores drive chars in a list and blanks them on the cmdline
  18. ; 5) Keeps filenames on cmdline as ASCIIZ with pointers in a list
  19.  
  20. ; DOS command:     FOOBAR/sw1/sw2 a: file1/sw3 file2   <cr>
  21. ; 81h after caps:        /SW1/SW2 A: FILE1/SW2 FILE2   <0>
  22. ; 81h after switches:             A: FILE1     FILE2   <0>
  23. ; 81h after drives:                  FILE1     FILE2   <0>
  24. ; 81h after filenames:               FILE1<0>  FILE2<0><0>
  25. ; Switch buffer:         /SW1/SW2/SW3<0>
  26.  
  27. ; USAGE: call cmdline 
  28. ;     lea si,switch_buffer  ; Scan ASCIIZ string for switches
  29. ;        mov al,drive1           ; AL contains drive *char*     
  30. ;        mov dx,filename1      ; DX contains address of string
  31. ;        mov dx,filename2... etc
  32.  
  33. ;----------------------------------------------------------------
  34.  
  35. SWITCH_BUFFER    db 64 dup 0    ;will be ASCIIZ string of switches
  36. SWB_SIZE    = ($-OFFSET switch_buffer)-1 ;-1 preserves zero byte
  37.  
  38. DRIVE1        db    0    ;will be drive char in caps
  39. DRIVE2        db    0    ;  in order found on cmd line
  40. DRIVE3        db    0
  41. DRIVE4        db    0
  42. MAX_DRIVES    = $-OFFSET drive1
  43.  
  44. FILENAME1    dw    0    ;will point to ASCIIZ *strings*
  45. FILENAME2    dw    0    ;  in order found on cmd line.
  46. FILENAME3    dw    0
  47. FILENAME4    dw    0    ;you may add more if you need them
  48. MAX_FILES    = ($-OFFSET filename1)/2
  49.  
  50. ;----------------------------------------------------------------
  51. ; Procedure begins here. The command line (tail) CS:80h = # chars
  52. ; on cmdline including ALL blanks (eg the first n after a filename)
  53. ; but not including the terminating return (0Dh). The first char is
  54. ; at 81h and may be "/" as in "FOOBAR/SWITCH". Redirection <>| is
  55. ; not saved and cannot be read here.
  56.  
  57. CMDLINE:    test    B[80h]        ;anybody home?
  58.         jz    ret        ;no (but it will be NZ even
  59.                     ;if blanks and no data)
  60.  
  61. ; These calls must be performed in the following order
  62.  
  63.         call    cmd_caps
  64.         call    cmd_switches    
  65.         call    cmd_drives
  66.         call    cmd_files
  67.         ret
  68.  
  69. ;----------------------------------------------------------------
  70.  
  71. CMD_CAPS:    mov    bx,81h        ;zero the cr at end of cmdline
  72.         add    bl,[bx-1]B    ;bx -> cr
  73.         mov    B[bx],bh    ;bh is zero
  74.  
  75.         mov    si,81h        ;where to get
  76.         mov    di,si        ;where to put
  77. L1:        lodsb            ;get
  78.         or    al,al        ;zero is end of cmdline
  79.         jz    ret        ;A86 will find an address
  80.         cmp    al,'a'        ;little a?
  81.         jb    >l2        ;too small
  82.         cmp    al,'z'        ;little z?
  83.         ja    >l2        ;too big
  84.         and    al,5Fh        ;mask out lower case bit
  85. L2:        stosb            ;put
  86.         jmp    l1        ;do more
  87.  
  88. ;----------------------------------------------------------------
  89. ; Switch "/" and following chars put in our buffer until a space or
  90. ; zero byte found. This reads multiple switches such as /aaaa/bb...
  91. ; as well as switches separated by a space. NOTE: When you process
  92. ; the buffer, a switch is terminated by "/" (another switch) or
  93. ; a zero byte (end of buffer).
  94.  
  95. CMD_SWITCHES:    mov    si,81h        ;where get
  96.         lea    di,switch_buffer ;where put
  97.         mov    cl,swb_size    ;buffer size
  98.  
  99. L1:        lodsb            ;get
  100.         or    al,al        ;end of cmdline?
  101.         jz    ret        ;yes, done
  102.         cmp    al,'/'        ;switch char?
  103.         jne    l1        ;no
  104.  
  105. L2:        or    cl,cl        ;buffer full?
  106.         jz    >l3        ;yes
  107.         stosb            ;put it in buffer
  108.         dec    cl        ;one less buffer byte available
  109. L3:        mov    B[si-1],' '    ;blank char on command line
  110.         lodsb            ;get next
  111.         cmp    al,' '        ;end of it?
  112.         ja    l2        ;no, must be a char
  113.         je    l1        ;space, keep scanning cmdline
  114.         ret            ;must be a zero byte so done
  115.  
  116. ;----------------------------------------------------------------
  117. ; Drives are the char before ':' when ':' is followed by space or zero
  118. ; "/DRIVE=x:" has been removed by the switch routine. "A:FILENAME" is
  119. ; not a drive because a char follows ":" "A:/SWITCH" is a drive because
  120. ; "/SWITCH" is now blank (by the switch routine).
  121.  
  122. CMD_DRIVES:    mov    si,81h        ;where get
  123.         lea    di,drive1    ;where put
  124.         mov    cl,max_drives    ;number allowed
  125.  
  126. L1:        lodsb            ;get
  127.         or    al,al        ;end of it?
  128.         jz    ret        ;yes
  129.         cmp    al,':'        ;possible drive?
  130.         jne    l1        ;no
  131.         mov    dl,[si]        ;peek next char (don't bump si)
  132.         cmp    dl,' '        ;space?
  133.         ja    l1        ;bigger, must be a char
  134.  
  135.         mov    al,[si-2]    ;get the drive letter
  136.         mov    W[si-2],2020h    ;blank "x:"
  137.         or    cl,cl        ;room for more?
  138.         jz    l1        ;no, don't save (table full)
  139.         stosb            ;save it (bumps di)
  140.         dec    cl        ;one less
  141.         jmp    l1
  142.  
  143. ;----------------------------------------------------------------
  144. ; Search for filenames inserting the pointer into table and
  145. ; terminating each with ASCIIZ. You may change the number of file
  146. ; names you expect in the table. Maximum is the entire command line
  147. ; allowing one char and a space for each filename!
  148.  
  149. CMD_FILES:    mov    si,81h        ;where get
  150.         lea    bx,filename1    ;where put
  151.         mov    cl,max_files    ;how many
  152.  
  153. L1:        mov    B[si-1],0    ;done on entry, but no harm
  154. L2:        lodsb            ;get
  155.         cmp    al,' '        ;space?
  156.         je    l2        ;yes, ignore leading spaces
  157.         jb    ret        ;below " " so zero byte, exit
  158.         or    cl,cl        ;a char, empty table entry left?
  159.         jz    >l3        ;no, don't save but do cmdline
  160.  
  161.         mov    [bx],si        ;save pointer
  162.         dec    W[bx]        ;  but si pointed one too far
  163.         add    bx,2        ;bx -> next filename
  164.         dec    cl        ;one less
  165.  
  166. L3:        lodsb            ;now look for end of filename
  167.         cmp    al,' '        ;space?
  168.         ja    l3        ;char so keep going
  169.         je    l1        ;space, insert zero byte
  170.         ret            ;must be zero so cmd line done
  171.  
  172. ; END CMDLINE.INC
  173.